#name : updateRS.pl
#author : Alexandre DUVAL
#mail : alexandre.duval@nantes.fr
#create date : 07.21.2010
#modified : 11.16.2010	

	
#! usr/bin/perl -w  
use strict;
use updteRsUtils qw(:DEFAULT);
use updateRsSub qw(:DEFAULT);


###################################Main program#######################################################################################

sub main
{
	
	my $ConfigFile = "ConfigUpdateRs.ini";
	my %ini=();
	
	%ini=READ_CONFIG_INIFILE($ConfigFile);
	my %general =%{$ini{"GENERAL"}};
	my %database = %{$ini{"DATABASE"}};
	my %dataIn = %{$ini{"IN"}};
	my %out = %{$ini{"OUT"}};
	
	my $build =$database{"build"};
 	my $dbDIR=$database{"path"};
	my $pathDataBIM=$dataIn{"pathBim"};
	my $pathDataFREQ=$dataIn{"pathFreq"};
	my $outdir=$out{"path"}."/report";
	my $dirws=$out{"path"}."/workspace";
	
	my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); #for integrated date (US format) in out file name
        my $date =  ($mon+1).$mday.(1900+$year);
	
	#MAKEDIRE($dirws); # create a temporary folder to work
	MAKEDIRE($outdir);# create a report folder

	print "\n*************************************************************************\n";
   	print "\n*                       UpDateRSname version 1.0                        *\n";
	print "*                                                                       *\n";	                       	                                    
	print "*   		       @ author : Alexandre DUVAL                       *\n";
	print "*                      @ mail : alexandre.duval@ nantes.fr              *\n";
	print "*                      @ create date : 05.11.2010                       *\n";
	print "*                      @ modified : 16.11.2010                          *\n";
   	print "\n*************************************************************************\n";
	

		opendir (DIR, $pathDataBIM) or die "Cannot openDIR : $pathDataBIM"  ;
		my @rep = readdir(DIR);


		foreach my $file (@rep)
		{ 
		
			if(-e "$pathDataBIM/$file")  
			{
				if(($file ne ".") && ($file ne ".."))
				{	
					
					UPDATERSNAME($dirws,\%database,$build,$pathDataBIM, $pathDataFREQ,$file, $outdir,$date);
					print "\n*******PROCESS COMPLETED FOR FILE : $file *******\n";
				}
				else
				{
					next;
				}					 
			}
			else
			{
				print "\n*********PROCESS FAILED : $file not exist***********\n";
			}  					
		}
	print "\n*********************************ALL DONE********************************\n";
}

main();

